package com.mentaleye.biz.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.SpecialtimeBean;
import com.mentaleye.biz.SpecialtimeBiz;
import com.mentaleye.dal.model.Specialtime;
import com.mentaleye.dal.model.SpecialtimeExample;
import com.mentaleye.service.SpecialtimeService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;

@Service
public class SpecialtimeBizImpl implements SpecialtimeBiz {
	private static Logger logger = Logger.getLogger(SpecialtimeBizImpl.class);
	@Autowired
	private SpecialtimeService specialtimeService;
	public CommonResult SpecialtimeEdit(SpecialtimeBean specialtimeBean) {
		CommonResult result=null;
		try{
			result=new CommonResult(); 
			boolean success = true;
			boolean add = specialtimeBean.getSwId() ==null;
			if(add){
				success=specialtimeService.Specialtimeinsert(specialtimeBean);				
			}else{
				success=specialtimeService.Specialtimeupdate(specialtimeBean);
			}
			result.setIsSuccess(success);
		} catch(Exception e){
			logger.error("错误", e);
		}
		return result;
	}

	@Override
	public CommonResult Specialtimeupdate(SpecialtimeBean specialtimeBean) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CommonResult SpworktimeByListupdate(List<Integer> ids, SpecialtimeBean specialtimeBean) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CommonResult Specialtimedelete(List<Integer> ids) {
		try{
		return new CommonResult(specialtimeService.Specialtimedelete(ids));
		}catch (Exception e){
			logger.error("删除异常",e );
			return new CommonResult();
		}
	}

	@Override
	public List<Specialtime> Specialselect(SpecialtimeExample example) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SpecialtimeBean Spworktimequery(Integer swId) {
		try {
			return specialtimeService.Spworktimequery(swId);
		} catch (Exception e) {
			logger.error("查询异常",e);
		}
		return null;
	}

	@Override
	public CommonResult SpecialtimeNotIndelete(List<Integer> ids) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void SpWorktimeByPagequery(CommonPage commonpage) {
	  try{
		  specialtimeService.SpWorktimeByPagequery(commonpage);
		 
	  }catch(Exception e){
       logger.error("查询特殊工作时间异常",e);
	  }
	}
	
	@Override
	public List<SpecialtimeBean> queryByYearAndMouth(String year,String mouth){
		List<SpecialtimeBean> list = null;
		try {
			Map<String, String> map = new HashMap<String,String>();
			map.put("year", year);
			map.put("mouth", mouth);
			list = specialtimeService.queryByBeginTimeAndEndTime(map);
		} catch (Exception e) {
			logger.error("查询某月节假日异常",e);
		}
		return list;
	}
	
	@Override
	public Date queryByMaxEndTime(String date){
		return specialtimeService.queryByMaxEndTime(date);
	}
	
	@Override
	public List<SpecialtimeBean> queryByBetWeenTime(String beginTime,String endTime){
		List<SpecialtimeBean> list = null;
		try {
			Map<String, String> map = new HashMap<String,String>();
			map.put("beginTime", beginTime);
			map.put("endTime", endTime);
			list = specialtimeService.queryByBetWeenTime(map);
		} catch (Exception e) {
			logger.error("查询范围内节假日异常",e);
		}
		return list;
	}

}
